package net.suncaper.demo.controller;

import com.sun.org.apache.xpath.internal.operations.Mod;
import net.suncaper.demo.domain.Admin;
import net.suncaper.demo.domain.Order;
import net.suncaper.demo.service.AdminService;
import net.suncaper.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Calendar;

@Controller
@RequestMapping("/admin")

public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/login")
    public String LoginGet(){
        return "/pages/login.html";
    }

    @PostMapping("/login")
    public String LoginPost(Admin admin, HttpServletRequest request ){
        //根据用户ID从数据库获得该ID的密码，然后判断
        int res = adminService.checkAdmin(admin);
        if( res == 2)//成功
        {
            //session
            HttpSession session=request.getSession();
            session.setAttribute("adminID",admin.getAdminid());
            return "/pages/widgets.html";
        }
        else{
            return "redirect:/admin/login";
        }
    }

}
